
local lflag = {}

lflag.setflag = function(bit, flagbit, bool)
    if bool then
        return bit | (1 << flagbit)
    else
        return bit & (~(1 << flagbit))
    end
end

lflag.hasflag = function(bit, flagbit)
    return (bit & (1 << flagbit)) ~= 0
end

lflag.tostring = function(bit, bitenum)
    local buff = {}
    for k,v in pairs(bitenum) do 
        if v ~= 0 and lflag.hasflag(bit, v) then 
            buff[#buff+1] = k
        end
    end 
    return table.concat(buff, '|')
end 

lflag.tobit = function(flag, bitenum)
    local v = 0
	for k in flag:gmatch '[^|]+' do
        if bitenum[k] then 
            v = v + bitenum[k]
        end 
	end
    return v
end




return lflag